@echo off
echo ================================
echo Carbon Planet - One-Click Start Tool
echo ================================
echo.

echo [1/4] Checking Node.js installation...
node --version >nul 2>nul
if %errorlevel% neq 0 (
    echo Error: Node.js not found!
    echo Please install Node.js from https://nodejs.org/
    pause
    exit /b 1
)

echo [2/4] Building project...
call npm install && call npm run build
if %errorlevel% neq 0 (
    echo Error: Build failed!
    pause
    exit /b 1
)

echo [3/4] Starting MongoDB...
set MONGODB_PATH=C:\Program Files\MongoDB\Server\8.0\bin\mongod.exe

if not exist "%MONGODB_PATH%" (
    echo MongoDB not found at default location.
    echo Please enter the full path to mongod.exe
    set /p MONGODB_PATH="MongoDB path: "
)

if not exist "%MONGODB_PATH%" (
    echo Error: MongoDB executable not found!
    echo Please install MongoDB and try again.
    pause
    exit /b 1
)

echo Found MongoDB at: %MONGODB_PATH%
for %%I in ("%MONGODB_PATH%") do set MONGODB_DRIVE=%%~dI
mkdir "%MONGODB_DRIVE%\data\db" 2>nul
start "MongoDB" "%MONGODB_PATH%" --dbpath "%MONGODB_DRIVE%\data\db"

echo [4/4] Starting the server...
start "Carbon Planet Server" cmd /c "node server.js"

echo.
echo ================================
echo All services have been started!
echo Local access: http://localhost:3000
echo.
echo Others in the local network can access via your IP address
echo ================================

pause 
